<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <div style="float: right;margin-right: 5px;">
        <el-button type="primary" size="mini" @click.stop="addWorkItem(id)">新增监测项</el-button>
      </div>
      <avue-crud
        :data="workingItemListData"
        :option="option"
        :page="page"
        :table-loading="tableLoading"
        @on-load="getWorkingItemPageList"
        @refresh-change="refreshChange"
        class="avuecrud"
      >
        <template slot-scope="scope" slot="menu">
          <div class="menu-title" @click.stop="editWorkingItem(scope.row,scope.index)">
            <i class="iconfont iconview icon-primary"></i>
            <p class="menu-title-text">编辑</p>
          </div>
          <!--<div class="menu-title" @click.stop="configureWorkingProgressFiled(scope.row,scope.index)">-->
            <!--<i class="iconfont iconalter icon-warning"></i>-->
            <!--<p class="menu-title-text">配置字段</p>-->
          <!--</div>-->
          <div class="menu-title" @click.stop="publishWorkingItem(scope.row,scope.index)" v-if="scope.row.state=='0'">
            <i class="iconfont iconpublish icon-warning"></i>
            <p class="menu-title-text">发布</p>
          </div>
        </template>
      </avue-crud>

    </div>
  </basic-container>
</template>

<script>
  import { modelDetail } from "@/api/pim/pim";
  import { workingItemPageList } from "@/api/pim/pim";
  import { publishWorkingItem } from "@/api/pim/pim";
  export default {
    name: "workingItemList",
    created(){
      this.id = this.$route.params.id
    },
    data(){
      return{
        headerData:{
          title:'监测项管理'
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        name:'',//模版名称
        workingItemListData: [],
        idsForm:{
          id:0
        },
        option: {
          page: true,
          addBtn: false,
          editBtn: false,
          indexLabel: "序号",
          index: true,
          cellBtn: false,
          indexWidth:70,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          menuWidth:160,
          keyId: "id",
          column: [{
            label: "监测项名称",
            width:380,
            prop: "name",
            cell: true
          },
            {
              label: "开始日期",
              prop: "startDate",
              cell: true
            },
            {
              label: "结束日期",
              prop: "endDate",
              cell: true
            },
            {
              label: "发布状态",
              prop: "state",
              cell: true,
              formatter: function (row, value, label, column) {
                if (row.state == '0') {
                  return "未发布";
                } else if (row.state == '1') {
                  return "已发布";
                }
              }
            },
          ]
        },
        tableLoading: false

      }
    },
    methods:{
     //新增监测项
      addWorkItem(id){
        let src = `/pim/addWorkItem/detail/${id}`;
        this.$router.push({
          path: src,
          query: {
            pmuc:this.$route.query.pmuc,
            titleName:this.$route.query.planningTitle,
          }
        })
      },
      //修改监测项
      editWorkingItem(row,index){
        let src = `/pim/editWorkingItem/detail/${row.id}`;
        this.$router.push({
          path: src
        })
      },
      //配置进度字段页面跳转
      configureWorkingProgressFiled(row,index){
        let src = `/pim/configureWorkingProgressFiled/index/${row.id}`;
        this.$router.push({
          path: src
        })
      },
      getWorkingItemPageList(page){
        this.tableLoading = true;
         workingItemPageList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          states:this.state,
           ditemId:this.$route.params.id,
        },)).then(response => {
          this.workingItemListData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false
        })
      },
      publishWorkingItem(row) {
        this.idsForm.id=row.id;
        this.$confirm("确定发布此监测项吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          publishWorkingItem(this.idsForm).then(response => {
            if (response.data.code == 0) {
              this.$notify({
                title: '成功',
                message: '发布成功',
                type: 'success',
                duration: 2000
              });
              this.$router.go(0);
            }
          })
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .card-border {
    border: 1px solid #d2d2d2;
    padding: 12px;
  }
  .form-submit {
    text-align: center;
  }
  .form-item{
    font-weight: 600;
  }
</style>
